package com.gongyibao.gbase.config;

import com.cvicse.inforsuitemq.command.InforsuiteMQTextMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.jms.*;


/**
 * @author sgw
 * @date 2019/07/11
 */
@Slf4j
@Configuration
public class ISMQProducer {

    @Autowired
    InforSuiteMQConfig inforSuiteMQConfig;

    public String send(String topic, String tag, String msg) {
        ConnectionFactory factory = inforSuiteMQConfig.connectionFactory();
        Connection connection = null;

        InforsuiteMQTextMessage message = new InforsuiteMQTextMessage();
        MessageProducer producer = null;
        Session session = null;
        try {
            connection = factory.createConnection();
            session = connection.createSession();
            Destination destination = session.createTopic(topic);
            producer = session.createProducer(destination);
            producer.setDeliveryMode(DeliveryMode.PERSISTENT);
            message.setText(msg);
            producer.send(destination, message);
        } catch (JMSException e) {
            throw new RuntimeException(e);
        } finally {

        }
        return null;
    }
}
